import React, { Component } from 'react';
import Store from '../../redux/Store';
import Action from '../../redux/Action';

class CityList extends Component {
	constructor(props) {
		super(props);
		this.state = {
			// province: Store.getState().cityList //接受父组件（Header）传递的城市列表数据
			province: props.province //接受父组件（Header）传递的城市列表数据
		};
	}
	componentWillUnmount = () => {
		this.setState = (state, callback) => {
			return;
		};
	};
	componentDidMount() {
		console.log(this.state.province);
		// console.log(Store.getState().cityList);
		// console.log(Store.getState().show);
	}
	//选择某个城市地址
	address = (city) => {
		// console.log(city)
		// console.log(this.state.province.name+city)
		Store.dispatch(Action.addKeyWord([this.state.province.name,city]));
		Store.dispatch(Action.show('temple'));
	};
	render() {
		const { province } = this.state;
		return (
			<div>
				<ul
					style={{
						background: '#fff',
						padding: '0 0.15rem',
						color: '#14141a',
						lineHeight: '0.56rem',
						fontSize: '0.15rem'
					}}
				>
					{province.cityList.map((item, index) => {
						return <li key={item + index} onClick={()=>this.address(item.name)}>{item.name}</li>;
					})}
				</ul>
			</div>
		);
	}
}

export default CityList;
